package com.hue.concurrent.day01;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/*
    FutureTask创建线程，能够获取线程执行的结果
    Future需要配合Callable使用
 */
public class Demo02 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<Integer> futureTask = new FutureTask<Integer>(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                System.out.println(Thread.currentThread().getName());
                return 1+2;
            }
        });

        //在main线程中执行任务
//        futureTask.run();

        //创建线程执行任务
        new Thread(futureTask).start();

        System.out.println(futureTask.get());
    }
}
